#define _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {

    if (list1 == NULL)
    {
        return list2;
    }

    if (list2 == NULL)
    {
        return list1;
    }

    struct ListNode* phead = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* tail = phead;

    while (list1 && list2)
    {
        if (list1->val > list2->val)
        {
            tail->next = list2;
            tail = list2;
            list2 = list2->next;
        }
        else
        {

            tail->next = list1;
            tail = list1;
            list1 = list1->next;

        }
    }

    if (list1)
    {
        tail->next = list1;
    }


    if (list2)
    {
        tail->next = list2;
    }

    struct ListNode* new = phead->next;
    free(phead);
    return new;

}

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
bool hasCycle(struct ListNode* head) {

    struct ListNode* fast = head;
    struct ListNode* slow = head;
    while (fast && fast->next)
    {

        fast = fast->next->next;
        slow = slow->next;

        if (fast == slow)
        {
            return true;
        }



    }


    return false;


}





